//
//  AddFriendViewController.m
//  QuanZiChat
//
//  Created by 张洪林 on 15/11/25.
//  Copyright © 2015年 ZhongHongLin. All rights reserved.
//

#import "AddFriendViewController.h"
#import "NameAddViewController.h"
#import "QRCodeGenerator.h"
#import <ZBarSDK.h>
@interface AddFriendViewController ()<UITableViewDelegate,UITableViewDataSource,ZBarReaderDelegate>
@property (weak, nonatomic) IBOutlet UITableView *FindTableView;
@property(nonatomic,strong)NSMutableDictionary *souceDic;

@end

@implementation AddFriendViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //获取列表
    NSArray *array = [[NSArray alloc]initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Find.plist" ofType:nil]];
    
    [self.souceDic setValue:array forKey:@"Find"];
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    NSArray * array = self.souceDic.allKeys;
    return array.count;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    NSArray * array = self.souceDic[self.souceDic.allKeys[section]];
    return array.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    NSArray * array = self.souceDic[self.souceDic.allKeys[indexPath.section]];
    cell.textLabel.text = array[indexPath.row][@"title"];
    return cell;
    
}
//点击方法
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            NameAddViewController *nVC = [self.storyboard instantiateViewControllerWithIdentifier:@"NameAddViewController"];
            [self.navigationController pushViewController:nVC animated:YES];
        }
        if ((indexPath.row == 1)) {
            //创建扫描界面
            ZBarReaderViewController *readVC = [self.storyboard instantiateViewControllerWithIdentifier:@"ZBarReaderViewController"];
            readVC.readerDelegate = self;
            //设置支持方向
            readVC.supportedOrientationsMask = ZBarOrientationMaskAll;
            //设置图片扫描器
            ZBarImageScanner *scanner = readVC.scanner;
            //配置扫描器
            [scanner setSymbology:ZBAR_I25 config:ZBAR_CFG_ENABLE to:0];
            
            [self showViewController:readVC sender:nil];
        }
    }
    
}

//懒加载
-(NSMutableDictionary *)souceDic{
    if (!_souceDic) {
        _souceDic = [NSMutableDictionary new];
    }
    return _souceDic;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
